package net.caixiaomi.info.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.TypedValue;
import android.widget.TextView;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.model.OrderRecordItem;

import java.util.List;

/**
 * 投注记录
 */

public class OrderRecordAdapter extends BaseQuickAdapter<OrderRecordItem, BaseViewHolder> {

    public OrderRecordAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    public OrderRecordAdapter(@LayoutRes int layoutResId, @Nullable List<OrderRecordItem> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderRecordItem item) {
        try {
            String orderStatus = item.getOrderStatus();
            int moreResId = R.mipmap.ic_greylight_arrow_right;
            int infoColor = ContextCompat.getColor(CommonApp.getInstance(), R.color.third_text);
            int infoTextSize = 10;
            int textColor = ContextCompat.getColor(CommonApp.getInstance(), R.color.primary_text);
            if (TextUtils.equals(orderStatus, "2") || TextUtils.equals(orderStatus, "4")) {
                textColor = ContextCompat.getColor(CommonApp.getInstance(), R.color.third_text);
            } else if (TextUtils.equals(orderStatus, "5")) {
                textColor = ContextCompat.getColor(CommonApp.getInstance(), R.color.orange_primary);
                infoColor = textColor;
                infoTextSize = 14;
                moreResId = R.mipmap.ic_orange_arrow_right;
            }
            helper.setImageResource(R.id.more, moreResId);
            StringBuilder stringBuilder = new StringBuilder();
            helper.setText(R.id.name, item.getLotteryName());
            helper.setText(R.id.status, item.getOrderStatusDesc());
            helper.setTextColor(R.id.status, textColor);
            stringBuilder.append(CommonApp.getInstance().getString(net.caixiaomi.info.R.string.C_MONEY_CHAT)).append(item.getTicketAmount());
            helper.setText(R.id.price, stringBuilder);
            helper.setText(R.id.time, item.getPayTime());
            TextView infoTextView = helper.getView(R.id.info);
            infoTextView.setTextColor(infoColor);
            infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP,infoTextSize);
            infoTextView.setText(item.getOrderStatusInfo());
            RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) helper.itemView.getLayoutParams();
            layoutParams.topMargin = (int) CommonApp.getInstance().getResources().getDimension(net.caixiaomi.info.R.dimen.padding_8);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
